import org.junit.Test;
import utils.C3p0Utils;
import utils.DBCPUtils;
import utils.DruidUtils;

import java.lang.annotation.Target;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by 郭浩 on 2020/9/23 16:05
 */
public class PoolTest {
    @Test
    public void dbcpTest() throws SQLException {
        Connection connection = null;

        connection = DBCPUtils.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement("select * from student");
        ResultSet resultSet = preparedStatement.executeQuery();
        resultSet.next();
        System.out.println(resultSet.getString("name"));
    }

    @Test
    public void c3p0Test() throws SQLException {
        Connection connection = null;

        connection = C3p0Utils.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement("select * from student");
        ResultSet resultSet = preparedStatement.executeQuery();
        resultSet.next();
        System.out.println(resultSet.getString("name"));
    }

    @Test
    public void druidTest() throws SQLException {
        Connection connection = DruidUtils.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement("select * from student");
        ResultSet resultSet = preparedStatement.executeQuery();
        resultSet.next();
        System.out.println(resultSet.getString("name"));
    }
}
